<template>
    <div>
        <el-form label-width="85px" :model="Document" ref="Document_refs">
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="文档编号" prop="ContractNumber">
                        <el-input v-model="Document.DocumentNumber"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="文档名称" prop="Title">
                        <el-input v-model="Document.Title"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="可见级别" prop="FileSeeType">
                        <el-select v-model="Document.FileSeeType" style="width: 100%">
                            <el-option label="高层" :value="1"></el-option> 
                            <el-option label="中高层" :value="2"></el-option>
                            <el-option label="全员" :value="4"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="文件类型" prop="FileType">
                        <el-select v-model="Document.FileType" style="width: 100%">
                            <el-option label="规章制度" :value="8"></el-option>
                            <el-option label="模板文件" :value="16"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="文件描述" prop="FileDescript">
                        <el-input v-model="Document.FileDescript"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="备注" prop="Remark">
                        <el-input v-model="Document.Remark"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="文档">
                        <UploadFileF ref="UploadFileF_AddDocument"
                                     :multiple="false"
                                     :another-data="AnotherData"
                                     :showfilelist="true"
                                     :upshow="false"
                                     content="上传文件"
                                     btnsize="medium"></UploadFileF>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col align="center">
                    <el-button type="success" @click="AddDocument_event">添加文档</el-button>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>

<script>
    import UploadFileF from "../UploadFileF";
    import * as IsExistjs from "../../../public/Scriput/IsExist";

    export default {
        name: "AddDocument",
        components:{
            UploadFileF,
        },
        data(){
            return{
                //文件上传参数
                AnotherData:{
                    FileType: 4,
                    id:0,
                    Type:0,
                    Single:true,
                },
                Document:{
                    DocumentNumber:'',
                    Title:'',
                    FileSeeType:'',
                    FileType:'',
                    FileDescript:'',
                    Remark:'',
                    FileName:'',
                    OperatId:0,
                    OperatDate:new Date(),
                    Delete:false,
                },
            }
        },
        created() {
            IsExistjs.IsExist.http(this.$http,this.$message)
        },
        methods:{
            async AddDocument_event(){
                let result = await IsExistjs.IsExist.IsExistDocumentNumber(this.Document.DocumentNumber)
                if (!result){
                    if (this.$refs['UploadFileF_AddDocument'].fileList.length > 0){
                        this.Document.FileName=this.$refs['UploadFileF_AddDocument'].fileList[0].name
                    }
                    this.$http.post('Document/AddDocumentContent',this.Document).then(res=>{
                        if (res.data.result){
                            this.$message.success('添加成功!')
                            this.$parent.$parent.AddDocument_dialog=false
                            this.$parent.$parent.formdata()
                            this.AnotherData.id = res.data.id
                            this.AnotherData.FileType = this.Document.FileType
                            if (this.$refs['UploadFileF_AddDocument'].fileList.length >0){
                                this.$refs['UploadFileF_AddDocument'].submitUpload()
                            }
                            this.$refs['Document_refs'].resetFields()
                        }else{
                            this.$message.warning('添加失败!')
                        }
                    })
                }else{
                    this.$message.info('此合同编号已存在,无法再次添加!')
                }
            },
        }
    }
</script>

<style scoped>

</style>
